// Copyright (c) Source Ltd. 2009-2010.
// 
// Source hereby grants to the user a worldwide, irrevocable,
// royalty-free, non-exclusive license to use this pre-existing
// intellectual property component for their own business purposes,
// limited in extent to that which is needed for the user to exploit work
// results completed by Source.
//
// If you have received this component apart from work produced by
// Source you are not authorised to use this component in your
// software.
//
// Any unauthorised copying of this file constitutes an infringement
// of copyright. All rights reserved.

#ifndef Log_LEVEL
#define Log_LEVEL (!defined(NDEBUG) ? Log_LEVEL_DEBUG : Log_LEVEL_OOPS)
#endif

#ifndef CONFIG_Log_Timing
#define CONFIG_Log_Timing (Log_LEVEL>Log_LEVEL_OOPS)
#endif

#define Log_LEVEL_DEBUG 3
#define Log_LEVEL_INFO 2
#define Log_LEVEL_OOPS 1
#define Log_LEVEL_NONE 0

#if Log_LEVEL >= Log_LEVEL_DEBUG
	#define Log_Debug(fmt,...) NSLog(@"DEBUG: %s %d " fmt, __PRETTY_FUNCTION__, __LINE__, ## __VA_ARGS__)
	#define Log_Oops(fmt,...)  NSLog(@"OOPS:  %s %d " fmt, __PRETTY_FUNCTION__, __LINE__, ## __VA_ARGS__)
#elif Log_LEVEL >= Log_LEVEL_OOPS
	#define Log_Debug(...) ((void)0)
	#define Log_Oops(fmt,...)  NSLog(@"OOPS: " fmt, ## __VA_ARGS__)
#else
	#define Log_Debug(...) ((void)0)
	#define Log_Debug(...) ((void)0)
#endif

#if CONFIG_Log_Timing
	#define Log_Timing(...) Log_Timing_(__PRETTY_FUNCTION__, __LINE__, @"" __VA_ARGS__)
#else
	#define Log_Timing(...) ((void)0)
#endif

#ifndef ASDevLog
#define ASDevLog Log_Debug
#endif

#ifndef ASLogNSError
#define ASLogNSError(e) Log_Debug(@"%@ desc='%@' fr='%@' rs='%@' ro=%@", e, [e localizedDescription], [e localizedFailureReason], [e localizedRecoverySuggestion], [e localizedRecoveryOptions])
#endif

#if CONFIG_Log_Timing && defined(__OBJC__)
@class NSString;

#ifdef __cplusplus
extern "C" {
#endif

void Log_Timing_(const char * tag, int line, NSString * fmt, ...) __attribute__((format (__NSString__, 3, 4)));

#ifdef __cplusplus
};
#endif

#endif
